﻿// 物体基类

using UnityEngine;

public abstract class ObjectBase : MonoBehaviour
{
    public virtual string GetTableName()
    {
        return gameObject.name;
    }
    public virtual long GetTableID()
    {
        return -1;
    }

    private long m_sceneID = -1;//场景对象id

    public long SceneID
    {
        get { return m_sceneID; }
    }

    static int m_ScenePointer = -1000;
    public static int GetScenePointer()
    {
        m_ScenePointer = m_ScenePointer--;
        return m_ScenePointer;
    }    // 初始化角色

    // 初始化角色
    public bool DoInit(long nID = -1, long sceneID = -1)
    {
        try
        {
            if (sceneID < 0)
                m_sceneID = GetScenePointer();//已赋值，则使用赋值的sceneID作为自己的ID，未赋值则本地会默认生成
            else
                m_sceneID = sceneID;
            OnInitID(nID);
            OnInitState();
            OnInitLogic();
        }
        catch (ExceptionSharpNull sharpnull)
        {
            XKLog.LogError(sharpnull.Message);
            return false;
        }
        return true;
    }

    void Update()
    {
        OnUpdate();
    }
    protected virtual bool OnUpdate()
    {
        return true;
    }

    protected virtual void OnInitID(long nID)
    {

    }
    protected virtual void OnInitState()
    {

    }
    protected virtual void OnInitLogic()
    {

    }


    public virtual AudioGroup GetAudioSource() { return null; }

    public virtual void DoSendStateEnterMessage(string strState)
    {

    }
}
